public class duplicateZeros {
    //复写零
    public void duplicateZeros(int[] arr) {
        int cur = 0,dest = -1,n = arr.length;
        while(cur<n){
            if(arr[cur] == 0){
                dest+=2;
            } else {
                dest++;
            }
            if(dest >= n-1) break;
            cur++;
        }
        if(dest==n){
            arr[n-1]=0;
            dest-=2;
            cur--;
        }
        for(;cur>=0;cur--){
            arr[dest--]=arr[cur];
            if(arr[cur]==0){
                arr[dest--]=0;
            }
        }
    }
}
